<?php
	include('functions.php');
	date_default_timezone_set('Europe/Copenhagen');	
	$runs = 10;
	
	// With or without safe and fsync
	if(isset($_GET['type'])) {
		$safe = true;
	} else {
		$safe = false;
	}

	l('Insert without index - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('insert_safe','0', $i) : query('insert','0', $i);
}

l('Update without index - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('update_safe','0', $i) : query('update','0', $i);
}

l('Delete without index - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('delete_safe','0', $i); ;  : query('delete','0', $i);
}
echo "<h1>Done</h1>";

// INDEX	
index('posts', array('post_title' => 1));

l('Insert with index on post_title - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('insert_safe','1', $i) : query('insert','1', $i);
}

l('Update with index on post_title - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('update_safe','1', $i);  : query('update','1', $i);
}

l('Delete with index on post_title - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('delete_safe','1', $i); ;  : query('delete','1', $i);
}

// INDEX	
$cursor = q('posts')->deleteIndexes(); 
index('posts', array('post' => 1));

l('Insert with index on post - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('insert_safe','1', $i) : query('insert','1', $i);
}

l('Update with index on post - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('update_safe','1', $i);  : query('update','1', $i);
}

l('Delete with index on post - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('delete_safe','1', $i); ;  : query('delete','1', $i);
}

// INDEX	
$cursor = q('posts')->deleteIndexes(); 
index('posts', array('post_title' => 1, 'rating' => 1));

l('Insert with index on post_title & Rating - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('insert_safe','1', $i) : query('insert','1', $i);
}

l('Update with index on post_title & Rating - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('update_safe','1', $i);  : query('update','1', $i);
}

l('Delete with index on post_title & Rating - Time: ' . date("d / m - Y H:i:s", time()));
for($i=0; $i<$runs; $i++) {
	set_time_limit(0);
	($safe) ? query('delete_safe','1', $i); ;  : query('delete','1', $i);
}

echo "DONE!";
?>